<?php
	class Model_sheep extends CI_Model{
		protected $_table = "tbl_sheep";
		protected $_album = "tbl_albums";
		protected $_rooms = "tbl_rooms";
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
        function getDateLast() {
            return $this->db
                ->select('sheep_id,sheep_end_last,sheep_last')
                ->where("sheep_status", 1)
                ->where("sheep_last",1)
                ->get($this->_table)->result_array();
        }
		public function listall($off,$start){
			$this->db->order_by("sheep_order","ASC");
			$this->db->limit($off,$start);
			return $this->db->get($this->_table)->result_array();
		}
		public function getallName_Id(){
			$query=$this->db->query("select sheep_id,sheep_name from tbl_sheep order by sheep_name");	
			return $query->result_array();
		}
		public function count_all(){
			return $this->db->count_all($this->_table);
		}
		public function getdata($id){
			$this->db->where("sheep_id",$id);
			return $this->db->get($this->_table)->row_array();
		}
		public function add($value){
			$this->db->insert($this->_table,$value);
		}
		public function update_status($data,$id){
			$this->db->where("sheep_id",$id);
			$this->db->update($this->_table,$data);
		}
		public function update($data,$id){
			$this->db->where("sheep_id",$id);
			$this->db->update($this->_table,$data);
		}
		public function albums(){
			$this->db->order_by("album_order","DESC");
			return $this->db->get($this->_album)->result_array();
		}
		public function del($id){
			$this->db->where("sheep_id",$id);
			$this->db->delete($this->_table);
		}
		public function getrooms($ship_id){
			$this->db->where("sheep_id",$ship_id);
			return $this->db->get($this->_rooms)->result_array();
		}
		public function check_table($name,$id=""){
			if($id != ""){
				$this->db->where("sheep_id !=",$id);
			}
			$this->db->where("sheep_name",$name);
			if($this->db->count_all_results($this->_table) != 0){
				return TRUE;	
			}else{
				return FALSE;
			}
		}
	}